]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
StScrollViewFade: Fix GLSL shader to work on r300 hardware
authorAdel Gadllah <adel.gadllah@gmail.com>
Sun, 13 Mar 2011 11:52:30 +0000 (12:52 +0100)
committerAdel Gadllah <adel.gadllah@gmail.com>
Sun, 13 Mar 2011 15:29:18 +0000 (16:29 +0100)
The number instructions in a shader is limited to 64 on r300 hardware,
the fade shader in StScrollViewFade was ending up using 97 instructions
which is way over the limit.

So refactor the shader to use less instructions by precomputing as many
values as possible outside of the conditionals. The resulting shader
ends up using 34 instructions which is well within the hardware limits.

https://bugzilla.gnome.org/show_bug.cgi?id=644589

src/st/st-scroll-view-fade.c

index 3d6639ae977e882695f0f10f465657522c056b46..74e430de2e0610a46326289bc4e110620838c86f 100644 (file)
@@ -49,21 +49,23 @@ static const gchar *fade_glsl_shader =
 " vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy));\n"
 " float y = height * cogl_tex_coord_in[0].y;\n"
 " float x = width * cogl_tex_coord_in[0].x;\n"
-" float ratio = 0.0;\n"
+" float ratio = 1.0;\n"
 " float fade_bottom_start = height - offset_bottom;\n"
-" \n"
-" if (offset_top != 0.0 && y < offset_top && ((rtl && x > scrollbar_width) || (!rtl && x < (width - scrollbar_width)))) {\n"
-"  ratio = y / offset_top;\n"
-"  cogl_color_out = color * ratio;\n"
-" }\n"
-" else if (offset_bottom != 0.0 && y > fade_bottom_start && ((rtl && x > scrollbar_width) || (!rtl && x < (width - scrollbar_width)))) {\n"
-"  ratio = (height - y)/(height - fade_bottom_start);\n"
-"  cogl_color_out = color * ratio;\n"
+" float ratio_top = y / offset_top;\n"
+" float ratio_bottom = (height - y)/(height - fade_bottom_start);\n"
+" bool in_scroll_area = ((rtl && x > scrollbar_width) || (!rtl && x < (width - scrollbar_width)));\n"
+" bool fade_top = y < offset_top && in_scroll_area;\n"
+" bool fade_bottom = y > fade_bottom_start && in_scroll_area;\n"
+"\n"
+" if (fade_top) {\n"
+"  ratio = ratio_top;\n"
 " }\n"
-" else { \n"
-"  cogl_color_out = color;\n"
+" else if (fade_bottom) {\n"
+"  ratio = ratio_bottom;\n"
 " }\n"
-"}\n";
+"\n"
+"  cogl_color_out = color * ratio;\n"
+"}";
 
 struct _StScrollViewFade
 {